package cn.bgs.service.impl;

import cn.bgs.mapper.BuildingMapper;
import cn.bgs.mapper.CellMapper;
import cn.bgs.pojo.Building;
import cn.bgs.pojo.Community;
import cn.bgs.pojo.Portal;
import cn.bgs.service.IBuildingService;
import cn.bgs.service.ICommunityService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.bgs.vo.CommunityVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

import java.util.List;

/**
 * <p>
 * 楼栋表 服务实现类
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@Service
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements IBuildingService {

    @Autowired
    private BuildingMapper buildingMapper;
    @Autowired
    CellMapper cellMapper;


    @Override
    public List<Building> appFindBuilding(Integer communityId) {
        QueryWrapper<Building> wrapper = new QueryWrapper<>();

        wrapper.eq("community_id",communityId);

        return list(wrapper);

    }


    @Override
    public PageInfo<CommunityVo> page1(String communityId, String houseuse, String howmany, Integer pagesize, Integer pagenow) {
        if (pagenow == null) {
            pagenow = 1;
        }

        if (pagesize == null) {
            pagesize = 5;
        }

        PageHelper.startPage(pagenow, pagesize);
        List<CommunityVo> communityVoList = this.buildingMapper.findinfopc(communityId, houseuse, howmany);
        PageInfo<CommunityVo> c = new PageInfo(communityVoList);
        return c;
    }

    @Override
    public PageInfo<CommunityVo> page2(String communityId, String houseuse, String state, Integer pagesize, Integer pagenow) {
        if (pagenow == null) {
            pagenow = 1;
        }

        if (pagesize == null) {
            pagesize = 5;
        }
       PageHelper.startPage(pagenow,pagesize);
        List<CommunityVo> communityVoList = this.buildingMapper.findHousePc(communityId,houseuse,state);
        System.out.println("----------:"+communityVoList);
        PageInfo<CommunityVo> a = new PageInfo(communityVoList);
        return a;
    }

    @Override
    public void addCommunityPc(Building forms) {
        this.buildingMapper.addCommunityPc(forms);
        Integer buildingId = forms.getBuildingId();
        Integer communityId = forms.getCommunityId();
        this.cellMapper.addPc(communityId,buildingId);
    }

    @Override
    public void delPc(Integer id) {
        this.buildingMapper.delPc(id);
    }

    @Override
    public void updateBuildPc(Building formData) {
        this.buildingMapper.updateBuildPc(formData);
    }

    @Override
    public List<Building> loadPc(Integer id) {
        List<Building> building = this.buildingMapper.loadPc(id);
        return building;
    }

    @Override
    public void addPortalPc(Portal forms) {
        this.buildingMapper.addPortalPc(forms);
        String communityId = forms.getCommunityId();
        Integer portalId = forms.getPortalId();
        String buildingId = forms.getBuildingId();
        this.cellMapper.addsPc(communityId,buildingId,portalId);

    }

    @Override
    public void delPortalPc(Integer id) {
        this.buildingMapper.delPortalPc(id);

    }


}
